package solution;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-19
 * Time: 19:52
 */

//https://leetcode.cn/problems/find-pivot-index/submissions/396322448/
class Solution7 {
    public int pivotIndex(int[] nums) {
        int sum = 0;
        for (int i : nums) {
            sum +=i;
        }
        int sum1 = 0;
        for (int i = 0; i < nums.length; i++) {
            if (sum1 * 2 + nums[i] == sum) {
                return i;
            }
            sum1 += nums[i];
        }
        return -1;
    }
}
